#define _CRT_SECURE_NO_WARNINGS 1
#include<iostream>
#include<string>
#include<cstring>
#include<map>
using namespace std;
map<char, int> mp;
map<char, int> mp1;
string s;
string s1;
int main()
{
    int t;
    while (t--)
    {
        int n;
        cin >> n;
        mp.clear();
        mp1.clear();
        while (n--)
        {
            cin >> s;
            for (int i = 0; i < s.size(); i++)
            {
                if (s[i] == 'W') mp['W']++;
                else if (s[i] == 'U') mp['U']++;
                else if (s[i] == 'B') mp['B']++;
                else if (s[i] == 'G') mp['G']++;
                else if (s[i] == 'R') mp['R']++;
            }
        }
        int m;
        cin >> m;
        while (m--)
        {
            cin >> s1;
            for (int i = 0; i < s1.size(); i++)
            {
                if (s1[i] == 'W') mp1['W']++;
                else if (s1[i] == 'U') mp1['U']++;
                else if (s1[i] == 'B') mp1['B']++;
                else if (s1[i] == 'G') mp1['G']++;
                else if (s1[i] == 'R') mp1['R']++;
                else if (s1[i] == 'O') mp1['O']++;
            }
        }
        if (mp['W'] >= mp1['W'] && mp['U'] >= mp1['U'] && mp['B'] >= mp1['B'] && mp['G'] >= mp1['G'] && mp['R'] >= mp1['R'])
        {
            if (mp['W'] - mp1['W'] + mp['U'] - mp1['U'] + mp['B'] - mp1['B'] + mp['G'] - mp1['G'] + mp['R'] - mp1['R'] >= mp1['O'])
                cout << "YES" << endl;
            else
                cout << "NO" << endl;
        }
        else
            cout << "NO" << endl;

    }
    return 0;
}